package 算法.查找;

public class 二分查找 {
    public static void main(String[] args) {
        int[] arr={11,12,13,14,15,16,17};
        System.out.println(binarySearch(arr, 15));
    }
    public static int binarySearch(int[] arr,int number){
        int max=arr.length-1;
        int min=0;

        while (true){
            if(max<min){
                return -1;
            }
            int mid=(max+min)/2;
            if(number<arr[mid]){
                //1.number 在mid的左边
                max=mid-1;
            }else if(number>arr[mid]){
                //2.number 在mid的右边
                min=mid+1;
            }else{
                //3.number和mid相等
                return mid;
            }
        }


    }
}
